<?php
/**
 * @package LaravelBoot
 *
 * @internal
 *
 * @author mawenpei
 * @date 2019/4/1 13:31
 * @version
 */
namespace Modules\Admin\Main\Controllers;

use App\Http\Controllers\Controller;
use App\Models\Logistics;
use App\Models\ShopOrder;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Validator;

class GoodsOrderController extends Controller
{
    public function search(Request $request)
    {
        return view('main::goods_order_list',$request->all());
    }

    public function apiWuliu(){
        $data = Logistics::select('code','name')->get();
        $newArray = [];
        foreach ($data as $item){
            $newArray[] = ["label"=>$item->name,"value"=>$item->code];
        }
        return success($newArray);
    }

    public function apiSearch(Request $request)
    {
        $limit = $request->input('limit', 10); // 这个是接受参数
        $offset = $request->input('offset', 0);
        $data = [];

        $data['total'] = ShopOrder::query()->where("order_type","goods")->count();
        $data['items'] = ShopOrder::query()->where("order_type","goods")->with('detail')->take($limit)
            ->skip($offset)
            ->orderBy('id', 'desc')
            ->get();

        if (!empty($data['items'])) {
            foreach ($data['items'] as &$value) {
                if (!empty($value->phone)) {
                    $value->mobile_en = encrypt($value->phone);
//                    $value->phone = convert_mobile($value->phone);
                }
            }
        }

        return success($data);
    }

}